//
//  LoginController.swift
//  SnapKitTest
//
//  Created by jin on 2024/8/13.
//

import UIKit
import TangramKit

class LoginController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        
        title = "登录界面"
        
        // MARK: - 控件
        //添加一个根容器
        let container = TGRelativeLayout()
        //从安全区开始
        container.tg_top.equal(TGLayoutPos.tg_safeAreaMargin).offset(16)
        container.tg_bottom.equal(TGLayoutPos.tg_safeAreaMargin).offset(16)
        container.tg_left.equal(TGLayoutPos.tg_safeAreaMargin).offset(16)
        container.tg_right.equal(TGLayoutPos.tg_safeAreaMargin).offset(16)
        view.addSubview(container)
        
        //logo
        let logoView = UIImageView()
        logoView.image = UIImage(named: "Logo")
        logoView.tg_width.equal(100)
        logoView.tg_height.equal(100)
        logoView.tg_top.equal(100)
        logoView.tg_centerX.equal(0)
        container.addSubview(logoView)
        
        // MARK: - 底部容器
        let linear = TGLinearLayout(.vert)
        linear.tg_width.equal(.fill)
        linear.tg_height.equal(.wrap)
        linear.tg_bottom.equal(0)
        linear.tg_gravity = TGGravity.horz.center
        linear.tg_space = 30
        container.addSubview(linear)
        
        // MARK: - 手机号登陆按钮
        linear.addSubview(phoneLoginButton)
        
        // MARK: - 登陆按钮
        linear.addSubview(loginButton)
        
        // MARK: - 协议
        let agrementLabelView = UILabel()
        //设置标题
        agrementLabelView.text = "登录即表示你同意《用户协议》和《隐私政策》"
        
        //设置字体大小和颜色
        agrementLabelView.font = UIFont.systemFont(ofSize: 12)
        agrementLabelView.textColor = .gray
        
        agrementLabelView.tg_width.equal(.wrap)
        agrementLabelView.tg_height.equal(.wrap)
        
        linear.addSubview(agrementLabelView)
    }
    

    @objc func phoneLoginClick(_ s:UIButton) {
        print("点击按钮")
        let controller = MyController()
        navigationController?.pushViewController(controller, animated: true)
    }
    
    @objc func loginClick(_ s:UIButton) {
        print("点击按钮")
    }

    /// 手机号登录按钮
    /// 这是swift中的懒加载写法
    lazy var phoneLoginButton: UIButton = {
        let button = UIButton(type: .system)
        
        //设置标题
        button.setTitle("手机号登陆", for: .normal)
        
        //设置点击事件
        button.addTarget(self, action: #selector(phoneLoginClick(_:)), for: .touchUpInside)
        
        button.backgroundColor = .red
        
        //圆角大小
        button.layer.cornerRadius = 5
        
        //标题默认颜色
        button.setTitleColor(.white,for: .normal)
        
        //按下文本颜色
        button.setTitleColor(.gray,for: .highlighted)
        
        button.tg_width.equal(.fill)
        button.tg_height.equal(42)
        
        return button
    }()
    
    
    ///用户名和密码登录
    lazy var loginButton: UIButton = {
        let button = UIButton(type: .system)
        
        //设置标题
        button.setTitle("用户名和密码登录", for: .normal)
        
        //设置点击事件
        button.addTarget(self, action: #selector(loginClick(_:)), for: .touchUpInside)
        
        button.backgroundColor = .clear
        
        //圆角大小
        button.layer.cornerRadius = 21
        
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.red.cgColor
        
        //标题默认颜色
        button.setTitleColor(.red,for: .normal)
        
        //按下文本颜色
        button.setTitleColor(.gray,for: .highlighted)
        
        button.tg_width.equal(.fill)
        button.tg_height.equal(42)
        
        return button
    }()

}
